var tetrisPieceTestCase = {};

var TetrisPiece = it.koutifaris._tetris.TetrisPiece;
var srsRotationSystem = new it.koutifaris._tetris.SRSRotationSystem();
var PieceType = it.koutifaris._tetris.PieceType;

tetrisPieceTestCase.getTestCaseName = function() {
	return "TetrisPiece Test";
};

tetrisPieceTestCase.testRotationRight = function() {
	var pieceType = PieceType.I;
	var piece = new TetrisPiece(pieceType, srsRotationSystem);
	var expected = srsRotationSystem.getPieceMatrix(pieceType, 1);

	piece.rotate(+1);
	assertTrue(piece.getCurrentMatrix().equals(expected));
};

tetrisPieceTestCase.testRotationLeft = function() {
	var pieceType = PieceType.I;
	var piece = new TetrisPiece(pieceType, srsRotationSystem);
	var expected = srsRotationSystem.getPieceMatrix(pieceType, -1);

	piece.rotate(-1);
	assertTrue(piece.getCurrentMatrix().equals(expected));
};

tetrisPieceTestCase.testOSquaresIterator = function() {
	var dr = 1;
	var dc = 2;
	var pieceType = PieceType.O;
	var piece = new TetrisPiece(pieceType, srsRotationSystem);
	piece.setPosition(dr, dc);

	var iterator = piece.squaresIterator();
	var count = 0;
	while (iterator.hasNext()) {
		var square = iterator.next();

		assertTrue(dr <= square.r && square.r < dr + 2);
		assertTrue(dc <= square.c && square.c < dc + 2);
		count++;
	}
	assertEquals(4, count);
};